Class FastPriorityQueue

Summary

Fully Qualified Name: Zend\Stdlib\FastPriorityQueue
Implements: Iterator, Countable, Serializable

Description

This is an efficient implementation of an integer priority queue in PHP

This class acts like a queue with insert() and extract(), removing the elements from the queue and it also acts like an Iterator without removing the elements. This behaviour can be used in mixed scenarios with high performance boost.

Methods

Name Description Defined By
contains() Does the queue contain the given datum? FastPriorityQueue
count() Get the total number of elements in the queue FastPriorityQueue
current() Get the current element in the queue FastPriorityQueue
extract() Extract an element in the queue according to the priority and the order of insertion FastPriorityQueue
hasPriority() Does the queue have an item with the given priority? FastPriorityQueue
insert() Insert an element in the queue with a specified priority FastPriorityQueue
isEmpty() Check if the queue is empty FastPriorityQueue
key() Get the index of the current element in the queue FastPriorityQueue
next() Set the iterator pointer to the next element in the queue without removing the previous element FastPriorityQueue
remove() Remove an item from the queue FastPriorityQueue
rewind() Rewind the current iterator FastPriorityQueue
serialize() Serialize FastPriorityQueue
setExtractFlags() Set the extract flag FastPriorityQueue
toArray() Serialize to an array FastPriorityQueue
unserialize() Deserialize FastPriorityQueue
valid() Check if the current iterator is valid FastPriorityQueue

Method Details

contains()

Does the queue contain the given datum?

Parameter Name Type Description
$datum mixed

Returns: bool

count()

Get the total number of elements in the queue

Returns: int

current()

Get the current element in the queue

Returns: mixed

extract()

Extract an element in the queue according to the priority and the order of insertion

Returns: mixed

hasPriority()

Does the queue have an item with the given priority?

Parameter Name Type Description
$priority int

Returns: bool

insert()

Insert an element in the queue with a specified priority

Parameter Name Type Description
$value mixed
$priority int

Returns:

isEmpty()

Check if the queue is empty

Returns: bool

key()

Get the index of the current element in the queue

Returns: int

next()

Set the iterator pointer to the next element in the queue without removing the previous element

Returns:

remove()

Remove an item from the queue

This is different than {@link extract()}; its purpose is to dequeue an item.

Note: this removes the first item matching the provided item found. If the same item has been added multiple times, it will not remove other instances.

Parameter Name Type Description
$datum mixed

Returns: bool False if the item was not found, true otherwise.

rewind()

Rewind the current iterator

Returns:

serialize()

Serialize

Returns: string

setExtractFlags()

Set the extract flag

Parameter Name Type Description
$flag int

Returns:

toArray()

Serialize to an array

Array will be priority => data pairs

Returns: array

unserialize()

Deserialize

Parameter Name Type Description
$data string

Returns: void

valid()

Check if the current iterator is valid

Returns: bool

Top